/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is Forte for Java, Community Edition. The Initial
* Developer of the Original Code is Sun Microsystems, Inc. Portions
* Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.form;
import org.openide.*;
/** A Dialog which is displayed if some errors or warnings are issued during loading of a form.
* It displays the list of errors and allows to display details on each item.
*
* @author Ian Formanek
*/
public class ErrorLogDialog extends javax.swing.JPanel {
private FormEditor.ErrorLogItem[] errors;
/** Creates new form ErrorLogDialog */
public ErrorLogDialog(FormEditor.ErrorLogItem[] errors) {
this.errors = errors;
initComponents ();
textLabel1.setText (FormEditor.getFormBundle ().getString ("CTL_ErrorLogText1"));
textLabel2.setText (FormEditor.getFormBundle ().getString ("CTL_ErrorLogText2"));
detailsButton.setText (FormEditor.getFormBundle ().getString ("CTL_DETAILS"));
errorsList.setCellRenderer(new ErrorItemRenderer ());
errorsList.setListData (errors);
errorsList.getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
updateDetailsButton ();
}
public java.awt.Dimension getPreferredSize () {
java.awt.Dimension inh = super.getPreferredSize ();
return new java.awt.Dimension (Math.min (inh.width, 550), Math.min (inh.height, 200));
}
private void updateDetailsButton () {
detailsButton.setEnabled (errorsList.getSelectedIndices().length == 1);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
textPanel = new javax.swing.JPanel ();
textLabel1 = new javax.swing.JLabel ();
textLabel2 = new javax.swing.JLabel ();
errorsScrollPane = new javax.swing.JScrollPane ();
errorsList = new javax.swing.JList ();
detailsPanel = new javax.swing.JPanel ();
detailsButton = new javax.swing.JButton ();
setLayout (new java.awt.BorderLayout ());
setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(8, 8, 8, 8)));
textPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints1;
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (0, 0, 8, 0);
gridBagConstraints1.weightx = 1.0;
textPanel.add (textLabel1, gridBagConstraints1);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.weightx = 1.0;
textPanel.add (textLabel2, gridBagConstraints1);
add (textPanel, java.awt.BorderLayout.NORTH);
errorsList.addListSelectionListener (new javax.swing.event.ListSelectionListener () {
public void valueChanged (javax.swing.event.ListSelectionEvent evt) {
errorsListValueChanged (evt);
}
}
);
errorsScrollPane.setViewportView (errorsList);
add (errorsScrollPane, java.awt.BorderLayout.CENTER);
detailsPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints2;
detailsButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
detailsButtonActionPerformed (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.insets = new java.awt.Insets (0, 8, 0, 0);
gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints2.weighty = 1.0;
detailsPanel.add (detailsButton, gridBagConstraints2);
add (detailsPanel, java.awt.BorderLayout.EAST);
}//GEN-END:initComponents
private void detailsButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detailsButtonActionPerformed
FormEditor.ErrorLogItem eli = (FormEditor.ErrorLogItem)errorsList.getSelectedValue ();
if (eli != null) {
ErrorDetail ed = new ErrorDetail (eli.getThrowable ());
detDlg = TopManager.getDefault ().createDialog (new DialogDescriptor (
ed,
FormEditor.getFormBundle ().getString ("CTL_ErrorDetailTitle"),
true,
new Object[] { FormEditor.getFormBundle ().getString ("CTL_CLOSE") },
FormEditor.getFormBundle ().getString ("CTL_CLOSE"),
DialogDescriptor.BOTTOM_ALIGN,
null,
new java.awt.event.ActionListener() {
public void actionPerformed (java.awt.event.ActionEvent ev) {
detDlg.setVisible (false);
}
}
)
);
detDlg.show ();
}
}//GEN-LAST:event_detailsButtonActionPerformed
private void errorsListValueChanged (javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_errorsListValueChanged
updateDetailsButton ();
}//GEN-LAST:event_errorsListValueChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel textPanel;
private javax.swing.JLabel textLabel1;
private javax.swing.JLabel textLabel2;
private javax.swing.JScrollPane errorsScrollPane;
private javax.swing.JList errorsList;
private javax.swing.JPanel detailsPanel;
private javax.swing.JButton detailsButton;
// End of variables declaration//GEN-END:variables
private java.awt.Dialog detDlg;
class ErrorItemRenderer extends javax.swing.DefaultListCellRenderer {
public java.awt.Component getListCellRendererComponent(javax.swing.JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent (list, value, index, isSelected, cellHasFocus);
FormEditor.ErrorLogItem item = (FormEditor.ErrorLogItem)value;
String text;
if (item.getType () == FormEditor.ErrorLogItem.WARNING) {
text = java.text.MessageFormat.format (
FormEditor.getFormBundle ().getString ("FMT_WarningItem"),
new Object[] { item.getDescription () }
);
} else {
text = java.text.MessageFormat.format (
FormEditor.getFormBundle ().getString ("FMT_ErrorItem"),
new Object[] { item.getDescription () }
);
}
setText (" " + text); // the leading space provides empty border on the left side of the list // NOI18N
return this;
}
}
class ErrorDetail extends javax.swing.JPanel {
ErrorDetail (Throwable t) {
setBorder (new javax.swing.border.EmptyBorder (8, 8, 8, 8));
setLayout (new java.awt.BorderLayout (0, 8));
javax.swing.JTextArea detailArea = new javax.swing.JTextArea ();
// detailArea.setBackground ((java.awt.Color) javax.swing.UIManager.getDefaults ().get ("Label.background")); // NOI18N
java.io.StringWriter sw = new java.io.StringWriter ();
t.printStackTrace (new java.io.PrintWriter (sw));
detailArea.setText (sw.toString ());
javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane ();
jScrollPane1.setViewportView (detailArea);
add (jScrollPane1, java.awt.BorderLayout.CENTER);
}
public java.awt.Dimension getPreferredSize () {
java.awt.Dimension inh = super.getPreferredSize ();
return new java.awt.Dimension (Math.min (inh.width, 630), Math.min (inh.height, 300));
}
}
}
/*
* Log
* 4 Gandalf 1.3 2/15/00 Tran Duc Trung minor change to make
* jikes happy
* 3 Gandalf 1.2 1/15/00 Ian Formanek Final version of error
* log dialog
* 2 Gandalf 1.1 1/15/00 Ian Formanek I18N
* 1 Gandalf 1.0 1/11/00 Ian Formanek
* $
*/